<?php
/**
 * 后台视图设计
 * @author GL
 * @date 2018.8.27
 */

namespace App\Http\ViewComposers;

use Cache;
use Illuminate\Contracts\View\View;
use App\Model\Crm\MenuModel;
use illuminate\support\facades\route;

class CrmComposer
{

    public function __construct()
    {

    }

    /**
     * 绑定数据到视图.
     *
     * @param View $view
     * @return void
     */
    public function compose(View $view)
    {
        $where['status'] = 0;
        $where['access_id'] = session('userInfo.access_id');
        $menu = MenuModel::menuList($where);

        $menu_as = Route::current()->getName();

        list($first, $second) = explode('::', $menu_as);

        if($menu){
            $menu = getTree($menu, $first, $menu_as);
        }

        $view->with('menu',$menu);
    }
}